package scriptEngine

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/SyncMap"
	"sync"
)

type subscribesTopic struct {
	subscribes sync.Map
}

func (e *subscribesTopic) getOperationKeys(subscribe string) []string {
	val, err := SyncMap.GetValue(&e.subscribes, subscribe)
	if err != nil || val == nil {
		return make([]string, 0)
	}

	return val.([]string)
}

func (e *subscribesTopic) save(subscribe string, operationKeys []string) {
	SyncMap.SetValue(&e.subscribes, subscribe, operationKeys)
}

func (e *subscribesTopic) keys() []string {
	list := make([]string, 0)
	e.subscribes.Range(func(key, value any) bool {
		list = append(list, key.(string))
		return true
	})

	return list
}
